home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / DB_CLIPP / 2510.ZIP / TRSOURCE.EXE / ATNEXT.C < prev    next >
C/C++ Source or Header  |  1990-10-22  |  2KB  |  49 lines

  1. /*********
  2. * Atnext.c by Leonard Zerman
  3. * Placed in the public domain by Tom Rettig Associates, 10/22/1990.
  4. *
  5. * Syntax: ATNEXT( <expC>, <expC>, <expN> )
  6. * Return: The position of <n> occurance of char in string. 
  7. * Note  : Returns 0 if not found.
  8. ********/
  9.  
  10. #include "trlib.h"
  11.  
  12. TRTYPE atnext()                          /* declare the atnext function */
  13. {
  14.     char *instr;                    /* a pointer to the passed string */ 
  15.     char *c;                     /* a pointer to the char to be found */               
  16.     int  i, n, po_found;                  /* the position of the find */
  17.     
  18.     if (PCOUNT == 3 && ISCHAR(1) && ISCHAR(2) && ISNUM(3))                         
  19.     {                  
  20.         c     = _parc(1) ;
  21.         instr = _parc(2) ;             /* assign the address to instr */  
  22.         n     = _parni(3);
  23.     }
  24.     else                                     
  25.     {
  26.          _retni(ERRORNEG);                   /* return a syntax error */      
  27.          return;                               /* return from program */     
  28.     }
  29.     if ( n == 0 )              /* return because of invalid parameter */
  30.        _retni(0);
  31.  
  32.     po_found = 0;
  33.     for (i = 0; instr[i] ; i++ )        /* while not at end of string */    
  34.     {                                      /* and the count of n != 0 */
  35.          if (instr[i] == *c )                      /* if a char match */  
  36.          {
  37.             if (!(--n))           /* If this is the occurence we want */
  38.             {
  39.                po_found = ++i;                 /* return the position */
  40.                break;                 
  41.             }
  42.          }
  43.          
  44.     }
  45.     _retni(po_found); 
  46.     return;
  47. }
  48.  
  49.